<template>
<div style="height:100%">
  <div class="prdlist">
  <el-form ref="form" :model="form" label-width="80px">
  <el-form-item label="客户名称">
    <el-input v-model="form.username" readonly></el-input>
  </el-form-item>
  <el-form-item label="沟通时间">
    <el-col :span="11">
      <el-date-picker type="date" placeholder="选择日期" v-model="form.date1" style="width: 100%;"></el-date-picker>
    </el-col>
  </el-form-item>
  <el-form-item label="跟进阶段">
    <el-radio-group v-model="form.status">
      <el-radio :label="1">新客户</el-radio>
      <el-radio :label="2">沟通中</el-radio>
      <el-radio :label="3">有意向</el-radio>
      <el-radio :label="4">成交机率高</el-radio>
      <el-radio :label="5">即将购买</el-radio>
      <el-radio :label="6">完成购买</el-radio>
      <el-radio :label="7">无意向</el-radio>
    </el-radio-group>
  </el-form-item>
  <el-form-item label="沟通结果描述">
    <el-input type="textarea" v-model="form.comment"></el-input>
  </el-form-item>
  <el-form-item>
    <el-button type="primary" @click="addmeeting">保存</el-button>
    <el-button @click="goback">返回</el-button>
  </el-form-item>
</el-form>
<div style="margin: 10px;">
  <label>跟进记录</label>
  </div>
  <div>
  <el-table
    :data="tableData"
    stripe
    height="100%"
    border
    style="width: 98%;margin-left: 1%;">
    <el-table-column
      prop="dt"
      label="沟通时间"
      width="200">
    </el-table-column>
    <el-table-column
      prop="status"
      label="跟进状态"
      width="200">
    </el-table-column>
    <el-table-column
      prop="comment"
      label="结果描述">
    </el-table-column>
  </el-table>
  </div>
  </div>
</div>
</template>
<script>
import { getmeetings,addmeeting} from '@/api/policy'

  export default {
    name:'genjins',
    data() {
      return {
        tableData:[],
        page:1,
        total:0,
        form: {
          name: '极乐空间',
          region: '',
          date1: '',
          date2: '',
          delivery: false,
          type: [],
          resource: '',
          desc: '',
          memberid:this.$route.query.id,
         status:'',
        }
      }
    },
    mounted(){
      this.form.username=this.$route.query.name;
      this.getmeetings();
    },
    methods: {
      goback(){
this.$router.go(-1)
      },
      getmeetings(){

       getmeetings({id:this.$route.query.id,page:this.page,size:100 }).then(res => {
        if (res.code == 200) {
              this.tableData=res.result;
              for(var i=0;i<this.tableData.length;i++)
              {

               this.tableData[i].dt=this.getNowFormatDate( this.tableData[i].dt);
               if(this.tableData[i].status==1)
               {
this.tableData[i].status= '新客户';

               }
                         if(this.tableData[i].status==2)
               {
this.tableData[i].status= '沟通中';

               }
                         if(this.tableData[i].status==3)
               {
this.tableData[i].status= '有意向';

               }
                         if(this.tableData[i].status==4)
               {
this.tableData[i].status= '成交几率高';

               }
                         if(this.tableData[i].status==5)
               {
this.tableData[i].status= '即将购买';

               }
                         if(this.tableData[i].status==6)
               {
this.tableData[i].status= '完成购买';

               }
                         if(this.tableData[i].status==7)
               {
this.tableData[i].status= '无意向';

               }
          
 

              }
              document.getElementsByClassName('el-table__body-wrapper')[0].style.height='auto';
         } 
        else{
          this.$toast(res.message)
        }
      });

      },
      addmeeting(){
                console.log(this.form.date1)
                console.log(this.form.username+'/ww')
  if(!this.form.status)
        {
          this.$toast('跟进阶段未选择')
          return;

        }
        if(!this.form.username)
        {
          this.$toast('客户名称未输入')
          return;

        }
                if(!this.form.comment)
        {
          this.$toast('沟通结果未输入')
          return;
          
        }
                if(!this.form.date1)
        {
          this.$toast('沟通时间未输入')
          return;
          
        }

         var  d = new Date(this.form.date1);
         this.form.dt=d.getTime();
        
       this.$loadingshow();
  addmeeting(this.form).then(res => {
    this.$loadingclose();
        if (res.code == 200) {
             this.$toast('添加成功')
            this.form={};
            this.form.username=this.$route.query.name;
            this.form.memberid=this.$route.query.id;

            this.getmeetings(this.$route.query.id);
        } 
        else{
          this.$toast(res.message)
        }
      });


      },
      onSubmit() {
        console.log('submit!');
      },
          getNowFormatDate(dt) {
        var date = new Date(dt);
        var seperator1 = "-";
        var year = date.getFullYear();
        var month = date.getMonth() + 1;
        var strDate = date.getDate();
        if (month >= 1 && month <= 9) {
            month = "0" + month;
        }
        if (strDate >= 0 && strDate <= 9) {
            strDate = "0" + strDate;
        }
        var currentdate = year + seperator1 + month + seperator1 + strDate;
        return currentdate;
    },
    }
  }
</script>

<style lang="scss" scoped>
.prdlist{
  width:90%;
  height: 100%;
  margin: 2%;
}

</style>
